package cn.zy.amyan.client.factory;

import cn.zy.amyan.client.AyClient;
import cn.zy.amyan.client.handler.ClientInvocationHandler;

import java.lang.reflect.Proxy;

/**
 * 通过动态代理⽣成代理对象
 */
public class BeanFactory {
	private AyClient ayClient;

	public BeanFactory(AyClient ayClient) {
		this.ayClient = ayClient;
	}

	public <T> T getBean(Class<T> clazz) {
		return (T) Proxy.newProxyInstance(
				Thread.currentThread().getContextClassLoader(),
				new Class<?>[]{clazz},
				new ClientInvocationHandler(ayClient)
		);
	}
}